
SET BUILD_FOLDER="build"
if not exist %BUILD_FOLDER% (
    mkdir build
)

cd build

echo "Staring building and compile with CMake-MinGW64"

cmake .. -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -DWITH_GIF=ON -DWITH_GIF_EXTERNAL=ON -DWITH_GEOS=ON ^
         -DWITH_GEOS_EXTERNAL=ON -DWITH_EXPACT=ON -DWITH_EXPACT_EXTERNAL=ON -DWITH_GTest=ON -DWITH_GTest_EXTERNAL=ON ^
		 -DWITH_PROJ=ON -DWITH_PROJ_EXTERNAL=ON -DWITH_SQLite3=ON -DWITH_SQLite3_EXTERNAL=ON -DWITH_HDF4=ON -DWITH_HDF4_EXTERNAL=ON ^
		 -DWITH_Spatialite=ON -DWITH_Spatialite_EXTERNAL=ON -DWITH_OCI=ON -DWITH_OCI_EXTERNAL=ON -DWITH_Boost=ON -DWITH_Boost_EXTERNAL=ON ^
		 -DWITH_UriParser=ON -DWITH_UriParser_EXTERNAL=ON -DWITH_ZLIB=ON -DWITH_ZLIB_EXTERNAL=ON -DWITH_JSONC=ON -DWITH_JSONC_EXTERNAL=ON -DWITH_ICONV=ON -DWITH_ICONV_EXTERNAL=ON ^
		 -DWITH_EXPAT=ON -DWITH_EXPAT_EXTERNAL=ON -DWITH_CURL=ON -DWITH_CURL_EXTERNAL=ON ^
		 -DWITH_LibLZMA=ON -DWITH_LibLZMA_EXTERNAL=ON -DWITH_LibXml2=ON -DWITH_LibXml2_EXTERNAL=ON ^
		 -DWITH_TIFF=ON -DWITH_TIFF_EXTERNAL=ON -DWITH_JPEG=ON -DWITH_JPEG_EXTERNAL=ON -DWITH_GeoTIFF=ON -DWITH_GeoTIFF_EXTERNAL=ON ^
		 -DWITH_JBIG=ON -DWITH_JBIG_EXTERNAL=ON -DWITH_OpenCAD=ON -DWITH_OpenCAD_EXTERNAL=ON ^
		 -DWITH_OpenSSL=OFF -DWITH_PostgreSQL=OFF  -DWITH_WEBP=ON -DWITH_WEBP_EXTERNAL=ON ^
        -DCMAKE_INSTALL_PREFIX=../installed/mingw -G "CodeBlocks - MinGW Makefiles"
cmake --build . --config Release --target install

echo "Ending building and compile with CMake-MinGW64"
cd ..

echo "Starting GDAL python interface!"

SET GDAL_DLL="%cd%\installed\mingw\bin\*.dll"
SET GDAL_THIRD_PARTY_DLL="%cd%\build\third-party\install\bin\*.dll"
SET GDAL_PYTHON_DLL="%cd%\installed\mingw\lib\site-packages"
xcopy %GDAL_DLL% %GDAL_PYTHON_DLL% /s
xcopy %GDAL_THIRD_PARTY_DLL% %GDAL_PYTHON_DLL% /s

ren "%cd%\installed\mingw\lib\site-packages\libgif.dll" "gif.dll"

echo "Finishing GDAL python interface!"


SET BUILD_FOLDER_MSVC="build_msvc"
if not exist %BUILD_FOLDER_MSVC% (
    mkdir build_msvc
)

cd build_msvc

echo "Staring building and compile with CMake-VS2019"

cmake .. -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -DWITH_GIF=ON -DWITH_GIF_EXTERNAL=ON -DWITH_GEOS=ON ^
         -DWITH_GEOS_EXTERNAL=ON -DWITH_EXPACT=ON -DWITH_EXPACT_EXTERNAL=ON -DWITH_GTest=ON -DWITH_GTest_EXTERNAL=ON ^
		 -DWITH_PROJ=ON -DWITH_PROJ_EXTERNAL=ON -DWITH_SQLite3=ON -DWITH_SQLite3_EXTERNAL=ON -DWITH_HDF4=ON -DWITH_HDF4_EXTERNAL=ON ^
		 -DWITH_Spatialite=ON -DWITH_Spatialite_EXTERNAL=ON -DWITH_OCI=ON -DWITH_OCI_EXTERNAL=ON -DWITH_Boost=ON -DWITH_Boost_EXTERNAL=ON ^
		 -DWITH_UriParser=ON -DWITH_UriParser_EXTERNAL=ON -DWITH_ZLIB=ON -DWITH_ZLIB_EXTERNAL=ON -DWITH_JSONC=ON -DWITH_JSONC_EXTERNAL=ON -DWITH_ICONV=ON -DWITH_ICONV_EXTERNAL=ON ^
		 -DWITH_EXPAT=ON -DWITH_EXPAT_EXTERNAL=ON -DWITH_CURL=ON -DWITH_CURL_EXTERNAL=ON ^
		 -DWITH_LibLZMA=ON -DWITH_LibLZMA_EXTERNAL=ON -DWITH_LibXml2=ON -DWITH_LibXml2_EXTERNAL=ON ^
		 -DWITH_TIFF=ON -DWITH_TIFF_EXTERNAL=ON -DWITH_JPEG=ON -DWITH_JPEG_EXTERNAL=ON -DWITH_GeoTIFF=ON -DWITH_GeoTIFF_EXTERNAL=ON ^
		 -DWITH_JBIG=ON -DWITH_JBIG_EXTERNAL=ON -DWITH_OpenCAD=ON -DWITH_OpenCAD_EXTERNAL=ON ^
		 -DWITH_OpenSSL=OON -DWITH_OpenSSL_EXTERNAL=ON -DWITH_PostgreSQL=OFF  -DWITH_WEBP=ON -DWITH_WEBP_EXTERNAL=ON ^
		 -DCMAKE_INSTALL_PREFIX=../installed/msvc -G "Visual Studio 16 2019" -A x64

del /s %cd%\third-party\CMakeCache.txt
cmake --build . --config Release --target install

echo "Installing compiled dlls"
cd ..


SET GDAL_THIRD_PARTY_DLL="%cd%\build_msvc\third-party\install"
SET GDAL_PYTHON_DLL="%cd%\installed\msvc\bin"
for /R %GDAL_THIRD_PARTY_DLL% %%f in (*.dll) do copy %%f %GDAL_PYTHON_DLL%


ren "%cd%\installed\msvc\bin\libgif.dll" "gif.dll"

echo "Ending building and compile with CMake-VS2019"